package com.example.himalaya2.api;

import com.example.himalaya2.utils.Constants;
import com.ximalaya.ting.android.opensdk.constants.DTransferConstants;
import com.ximalaya.ting.android.opensdk.datatrasfer.CommonRequest;
import com.ximalaya.ting.android.opensdk.datatrasfer.IDataCallBack;
import com.ximalaya.ting.android.opensdk.model.album.GussLikeAlbumList;
import com.ximalaya.ting.android.opensdk.model.album.SearchAlbumList;
import com.ximalaya.ting.android.opensdk.model.track.TrackList;
import com.ximalaya.ting.android.opensdk.model.word.HotWordList;
import com.ximalaya.ting.android.opensdk.model.word.SuggestWords;

import java.security.Key;
import java.util.HashMap;
import java.util.Map;


public class XimalayaApi {

    /*
    * 获取推荐的内容
    * */

    private XimalayaApi() {}
    private static XimalayaApi sXimalayaApi;
    public static XimalayaApi getInstance(){
        if (sXimalayaApi == null) {
            synchronized (XimalayaApi.class) {
                if (sXimalayaApi == null) {
                    sXimalayaApi = new XimalayaApi();
                }
            }
        }
        return sXimalayaApi;
    }

    public void getRecommendList(IDataCallBack<GussLikeAlbumList> callBack) {
        Map<String, String> map = new HashMap<>();
        map.put(DTransferConstants.LIKE_COUNT, Constants.RECOMMAND_COUNT+"");
        CommonRequest.getGuessLikeAlbum(map,callBack);
    }

    public void getAlbumDetail(IDataCallBack<TrackList> callBack,long albumId,int pageIndex ) {
        Map<String,String> map = new HashMap<>();
        map.put(DTransferConstants.ALBUM_ID,albumId +"");
        map.put(DTransferConstants.SORT,"asc");
        map.put(DTransferConstants.PAGE_SIZE, Constants.COUNT_DEFAULT+"");
        map.put(DTransferConstants.PAGE,pageIndex+"");
        CommonRequest.getTracks(map,callBack);
    }

    /*
    * 更具关键词 进行搜索
    * */
    public void searchByKeyWord(String keyword, int page, IDataCallBack<SearchAlbumList> callBack) {
        Map<String,String> map = new HashMap<>();
        map.put(DTransferConstants.SEARCH_KEY,keyword);
        map.put(DTransferConstants.PAGE,page+"");
        map.put(DTransferConstants.PAGE_SIZE,Constants.COUNT_DEFAULT+"");
        CommonRequest.getSearchedAlbums(map,callBack);
    }

    /*
    * 获取推荐的热词
    * */
    public void getHotWord(IDataCallBack<HotWordList> callBack){
        Map<String,String> map = new HashMap<>();
        map.put(DTransferConstants.TOP, Constants.COUNT_HOT_WORD+"");
        CommonRequest.getHotWords(map,callBack);
    }

    /*
    * 获取联想词
    * */
    public void getSuggestWord(String keyWord,IDataCallBack<SuggestWords> callBack) {
        Map<String,String> map = new HashMap<>();
        map.put(DTransferConstants.SEARCH_KEY, keyWord);
        CommonRequest.getSuggestWord(map,callBack);
    }
}
